package org.zjx.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.tags.Tag;
import jakarta.annotation.PostConstruct;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

/**
 * ClassName: Knife4jConfig
 * Package: com.mcode.knife4jdemo.config
 * Description:
 *
 * @Author: robin
 * @Version: v1.0
 */
@Configuration
public class Knife4jConfig {

    @Bean
    public GroupedOpenApi adminApi() {      // 创建了一个api接口的分组
        return GroupedOpenApi.builder()
                .group("mhxy-server-api")         // 分组名称
                .pathsToMatch("/account/**","/dailyTask/**","/prop/**","/screen/**","/waypoint/**","/font/**",
                        "/npc/**")  // 接口请求路径规则
                .build();
    }

    @Bean
    public OpenAPI openAPI(){
        System.out.println("✅ OpenAPI配置加载成功");
        return new OpenAPI()
                .components(new Components())
                .info(new Info()
                        .title("Knife4j标题")
                        .description("Knife4j说明")
                        .version("v1")
                        .contact(new Contact().name("robin").email("robin@gmail.com"))
                        .license(new License().name("Apache 2.0").url("http://springdoc.org"))
                )
                // 接口排序
                .addTagsItem(new Tag()
                        .name("用户管理接口")
                        .description("用户相关操作接口")
                        .extensions(Collections.singletonMap("x-order", 1))
                );

    }

    @PostConstruct
    public void init() {
        System.out.println("✅ Knife4j配置类加载成功");
    }

}